﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
namespace River.IntAI
{
    public partial class FrmMain : Form
    {
        private int childFormNumber = 0;
        List<Form> _childForms = new List<Form>();
        public FrmMain()
        {
            InitializeComponent();
            BaseForm.MainStatusEvent += OnMainStatusEvent;
        }

        private void OnMainStatusEvent(string msg)
        {
            if (InvokeRequired)
                Invoke(new Action(() => { lbStatusInfo.Text = msg; }));
            else
                lbStatusInfo.Text = msg;
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
        }

        private void ShowForm(Form childForm)
        {
            var form = _childForms.Where(x => x.Name == childForm.Name && !x.IsDisposed).FirstOrDefault();
            if (form != null)
            {
                form.Activate();
                return;
            }

            childForm.MdiParent = this;
            childForm.WindowState = FormWindowState.Maximized;
            _childForms.Add(childForm);
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void 语音识别ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm(new FrmSpeech());
        }

        private void 文字识别ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm(new FrmOcr());
        }

        private void 语音合成ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm(new FrmSynthesis());
        }

        private void 关于AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm(new FrmAbout());
        }
    }

}
